﻿//
// GNS_UserTopUpDea.cpp
// MobileManageSys
//FuncTion 个人充值/兑奖详情
// Created by mr.l on 16/1/19.
//
//

#include "GNS_UserTopUpDea.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
#include "GNS_PlayerMgr.h"
USING_NS_CC;
using namespace cocostudio::timeline;
using namespace ui;

#define winsize Director::getInstance()->getVisibleSize()

GNS_UserTopUpDea::GNS_UserTopUpDea()
{
    pGNS_UserTopUpDea=0;
    SendText=nullptr;
    TypeText = nullptr;
    RecText = nullptr;
    GlodText=nullptr;
    RText = nullptr;
    DateText = nullptr;
    TimeText = nullptr;
}

GNS_UserTopUpDea::~GNS_UserTopUpDea()
{
    
}

GNS_UserTopUpDea* GNS_UserTopUpDea::createLayer()
{
    auto pGNS_UserTopUpDea = GNS_UserTopUpDea::create();
    auto pScene = Director::getInstance()->getRunningScene();
    if (!pScene)
        return 0;
    pScene->addChild(pGNS_UserTopUpDea);
    return pGNS_UserTopUpDea;
}

bool GNS_UserTopUpDea::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    return true;
}
void GNS_UserTopUpDea::SetNodeName(std::string CsbName)
{
    pGNS_UserTopUpDea = CSLoader::createNode(CsbName);
    pGNS_UserTopUpDea->setContentSize(winsize);
    ui::Helper::doLayout(pGNS_UserTopUpDea);
    addChild(pGNS_UserTopUpDea,11);
    GNS_PlayerMgr::getInstance()->_NodeChildVec.pushBack(pGNS_UserTopUpDea);
    auto pBackBtn = static_cast<Button*>(pGNS_UserTopUpDea->getChildByName("SysTTDetailsBtn"));
    pBackBtn->setTag(1);
    pBackBtn->addTouchEventListener(CC_CALLBACK_2(GNS_UserTopUpDea::BtnCallBack, this));
    
    SendText = static_cast<Text*>(pGNS_UserTopUpDea->getChildByName("SendID"));
    TypeText = static_cast<Text*>(pGNS_UserTopUpDea->getChildByName("TypeText"));
    RecText = static_cast<Text*>(pGNS_UserTopUpDea->getChildByName("RecText"));
    GlodText = static_cast<Text*>(pGNS_UserTopUpDea->getChildByName("GlodText"));
    RText = static_cast<Text*>(pGNS_UserTopUpDea->getChildByName("RText"));
    DateText = static_cast<Text*>(pGNS_UserTopUpDea->getChildByName("DateText"));
    TimeText = static_cast<Text*>(pGNS_UserTopUpDea->getChildByName("TimeText"));
    
}
void GNS_UserTopUpDea::BtnCallBack(cocos2d::Ref *pSender, ui::Widget::TouchEventType type){
    if (type==ui::Widget::TouchEventType::ENDED) {
        auto pButton = (Button*)pSender;
        int BtnTag = pButton->getTag();
        switch (BtnTag) {
            case 1:
            {
                if (GNS_PlayerMgr::getInstance()->_NodeChildVec.size()!=0) {
                    GNS_PlayerMgr::getInstance()->_NodeChildVec.erase(1);
                    this->removeAllChildrenWithCleanup(true);
                    this->getParent()->removeChild(this);
                }
                auto pUserTopUpNode=GNS_PlayerMgr::getInstance()->_NodeChildVec.at(0);
                pUserTopUpNode->setVisible(true);
                break;
            }
            default:
                break;
        }
    }
}
void GNS_UserTopUpDea::UpPopDate(CMD_SC_GetUserExchangeInfoResult pUserInfo,std::string str)
{
	//std::string TypeStr = GetTypeStr(pUserInfo._type);
    SendText->setString(StringUtils::format("%d",pUserInfo._sendCode));
	/*
	if(pUserInfo._type==1)
    {
        TypeText->setString("充值");
	}else if(pUserInfo._type == 3)
	{
		TypeText->setString("退回");
	}
	else
	{
        TypeText->setString("12344"); //兑奖
    }*/
	TypeText->setString(str);
    RecText->setString(StringUtils::format("%d",pUserInfo._revCode));
    GlodText->setString(StringUtils::format("%lld",pUserInfo._gold));
    DateText->setString(StringUtils::format("%s",pUserInfo._operTime)); 
    TimeText->setString(StringUtils::format("%s",pUserInfo._operDate));
    RText->setString(StringUtils::format("%lld",pUserInfo._rmb));
}